package net.xdclass.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
@Slf4j
public class SonwFlakeWorkIdConfig {

    static {
        try {
            InetAddress inetAddress = InetAddress.getLocalHost();

            String hostAddressIp = inetAddress.getHostAddress();

            String workId = Math.abs(hostAddressIp.hashCode()) % 1024 + "";

            System.setProperty("workId", workId);

            log.info("workId:{}", workId);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

}
